package cn.iutils.faq.controller;

import cn.iutils.common.Page;
import cn.iutils.common.ResultVo;
import cn.iutils.common.controller.BaseController;
import cn.iutils.faq.entity.Answers;
import cn.iutils.faq.service.AnswersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 知识问答 控制器
 * @author iutils.cn
 * @version 1.0
 */
@RestController
@RequestMapping("${restPath}/faq")
public class FaqRest extends BaseController {

    @Autowired
    private AnswersService answersService;

    /**
     * 获取回答分页列表
     * @param page
     * @return
     */
    @RequestMapping(value = "/answers/page", method = RequestMethod.GET)
    public @ResponseBody
    ResultVo page(Answers answers,Page<Answers> page) {
        ResultVo resultVo = null;
        try {
            page.setEntity(answers);
            page.setOrderBy("a.create_date desc");
            Page<Answers> rPage = page.setList(answersService.findPage(page));
            resultVo = new ResultVo(ResultVo.SUCCESS,"1","调用成功",rPage);
        }catch (Exception e){
            logger.error("获取回答分页列表接口调用失败",e.getMessage());
            resultVo = new ResultVo(ResultVo.FAILURE,"-1","调用失败",null);
        }
        return resultVo;
    }

}
